package gl.android.drag.fragmentdragback;

import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import gl.android.drag.fragmentdragback.R;
import gl.android.drag.fragmentdragback.DragLayout.DragListenter;

public class DragFragmentHelper {
	private Fragment fragment;

	public DragFragmentHelper(Fragment fragment) {
		this.fragment = fragment;
	}

	public View hookFragmentView(LayoutInflater inflater, ViewGroup container,
			int layoutId) {
		// Inflate the layout for this fragment
		DragLayout dragView = (DragLayout) inflater.inflate(
				R.layout.drag, container, false);
		ViewGroup view = (ViewGroup) inflater.inflate(layoutId, null, false);
		dragView.setDragView(view);
		dragView.setDragListenter(new DragListenter() {
			@Override
			public void onDragFinish() {
				fragment.getFragmentManager().beginTransaction()
						.detach(fragment).commit();
			}
		});
		return dragView;
	}

}
